<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Banner;
use Carbon\Carbon;
use \Cache;

class BannerController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function show(Request $request)
    {

        $this->validate($request, [
            'type' => 'nullable|numeric',//广告类型1轮播图
        ]);

        $banner = Banner::where('inttime', '<', Carbon::now())
            ->where('endtime', '>', Carbon::now())
            ->when($request->get('type'),function ($query){
                return $query->whereRaw('position(? in `type`)', request('type'));
            })
            ->orderBy('sort')
            ->paginate(15);

        return $this->successReturn($banner);
    }


}
